//
//  YWDBTool.h
//  maintain
//
//  Created by 郑想 on 15/10/10.
//  Copyright (c) 2015年 ewin. All rights reserved.
//

#import "FMDB.h"
#import <Foundation/Foundation.h>
#import "YWSingleton.h"

#import "YWEquipmentMaintenanceRecord.h"

#import "YWMission.h"
#import "YWPatrolPicture.h"
#import "YWPatrolPointRecord.h"
#import "YWPatrollineRecord.h"
#import "YWPicture.h"

#import "YWHandler.h"
#import "YWattachment.h"
#import "YWInspectionMissionModel.h"
#import "YWInspectionLineRecord.h"

@class YWEquipment;
@class YWBuilding;
@class YWApartment;
@class YWFloor;
@class YWLocation;
@class YWBuildingJson;
@class YWManufacturer;
@class YWCompany;
@class YWEquipmentTroubleRecord;
@class YWLastMaintenanceTime;
@class YWDictEquipmentRule;
@class YWEquipmentRuleRel;

@class YWMessage;

@class YWCirculationInfo;
@class YWMeterProperty;
@class YWEquipmentType;
@class YWEquipmentUseMenthod;
@class YWEquipmentUseRange;
@class YWReportTroubleModel;
@class YWTroubleMissionModel;
@class YWEquipmentSystemType;

@interface YWDBTool : NSObject
@property (nonatomic, strong, readonly) FMDatabase* fmdb;
@property (nonatomic, strong, readonly) FMDatabaseQueue* dbQeue;

YWSingletonH(DBTool)

/**
 *  登录成功后连接数据库
 *
 *  @param dbName 数据库的名称
 *
 *  @return 连接结果
 */
- (void)connectDB : (NSString*)dbName;
/**
 *  关闭数据库
 *
 *  @return 结果
 */
- (void)closeDatabase;
/**
 *  获取数据库存放路径
 *
 *  @return 路径
 */
- (NSString*)dbPath;

#pragma mark - dict_equipment_type table
/**
 *  首次批量新增设备类型数据
 *
 *  @param equipmentRuleRelArray 设备类型模型数组
 *
 *  @return 结果
 */
- (BOOL)insertDictEquipmentTypeWithArray:(NSArray*)dictEquipmentTypes;
/**
 *  设备类型
 *
 *  @return 结果
 */
- (NSArray *)allEquipmentTypeWithSystemId:(NSInteger)systemTypeId;
- (YWEquipmentType*)equipmentTypeWithFMResultSet:(FMResultSet*)set db:(FMDatabase*)db;
/**
 *  设备的系统类型
 *
 *  @return 结果
 */
- (NSArray *)allEquipmentSystemType;
/**
 *  设备的子系统类型
 *
 *  @return 结果
 */
- (NSArray *)allEquipmentSubSystemType;
/**
 *  设备系统类型对象
 *
 *  @return 结果
 */
- (YWEquipmentSystemType*)equipmentSystemTypeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  设备运行参数最大的createTime
 *
 *  @return 结果
 */
- (NSTimeInterval)dicEquipmentRuntimeParameterMaxCreateTime;
/**
 *  保存运行参数
 *
 *  @return 结果
 */
- (BOOL)saveRuntimeParameterWithArray:(NSArray*)runtimeParameterArray;

/**
 *  获取设备类型表里的最大的更新时间
 *
 *  @return UpdateTime
 */
- (NSTimeInterval)dicEquipmentTypeMaxUpdateTime;
/**
 *  获取设备类型名称
 *
 *  @param equipmentTypeId 类型Id
 *
 *  @return 名称
 */
- (NSString*)equipmentTypeNameWithTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取设备（水电燃气等）类型Id
 *
 *  @param  ownCode 设备标识（水电燃气等）
 *
 *  @return 设备（水电燃气等）类型Id
 */
- (NSInteger)equipmentTypeIdWithOwnCode:(NSString*)ownCode;
/**
 *  获取设备运行参数
 *
 *  @param  equipmentTypeId 设备类型id
 *  @param  maintenanceTypeId 维保类型id
 *
 *  @return 数组
 */
- (NSArray*)equipmentFieldsWithTypeId:(NSInteger)equipmentTypeId maintenanceTypeId:(NSInteger)maintenanceTypeId;
/**
 *  保存设备自定义属性的记录
 *
 *  @param  equipmentFieldRecords 设备自定义属性数组
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentFieldRecords:(NSArray*)equipmentFieldRecords;
/**
 *  获取设备自定义属性的记录
 *
 *  @param  uniqueTag 记录标识
 *  @param  maintenanceTypeId 维保类型Id
 *
 *  @return 结果
 */
- (NSArray*)equipmentFieldRecordsWithUniqueTag:(NSString*)uniqueTag maintenanceTypeId:(NSInteger)maintenanceTypeId;

#pragma mark - dict_equipment_rule table
/**
 *  更新规则关系
 *
 *  @param equipmentRuleRel 设备规则关系对象
 */
- (void)updateEquipmentRuleRel:(YWEquipmentRuleRel*)equipmentRuleRel;
/**
 *  更新规则
 *
 *  @param dictEquipmentRule 设备规则对象
 */
- (void)updateDictEquipmentRule:(YWDictEquipmentRule*)dictEquipmentRule;
/**
 *  首次批量新增规则数据
 *
 *  @param equipmentRuleRelArray 规则模型数组
 *
 *  @return 结果
 */
- (BOOL)insertDictEquipmentRuleWithArray:(NSArray*)dictEquipmentRule;
/**
 *  获取规则
 *
 *  @param equipmentTypeId   设备类型id
 *  @param maintenanceTypeId 维保类型id
 *
 *  @return 规则模型数组
 */
- (NSArray*)rulesWithEquipmentTypeId:(NSInteger)equipmentTypeId maintenanceTypeId:(NSInteger)maintenanceTypeId maintenanceCycleId:(NSInteger)maintenanceCycleId;

#pragma mark - equipment_rule_rel table
/**
 *  首次批量新增设备-规则关系数据
 *
 *  @param dictEquipmentRule 设备规则关系模型数组
 *
 *  @return 结果
 */
- (BOOL)insertEquipmentRuleRelWithArray:(NSArray*)equipmentRuleRelArray;


#pragma mark - equipment table
/**
 *  判断二维码下是否有设备
 *
 *  @param qrcodeId 二维码id
 *
 *  @return 结果
 */
- (BOOL)isExistEquipmentWithQrcodeId:(NSString*)qrcodeId;
/**
 *  判断位置下是否有设备
 *
 *  @param locationId 位置id
 *
 *  @return 结果
 */
- (BOOL)isExistEquipmentWithLocationId:(NSInteger)locationId;
/**
 *  首次批量新增设备数据
 *
 *  @param equipmentsArray 设备模型数组
 *
 *  @return 结果
 */
- (BOOL)insertEquipmentWithArray:(NSArray*)equipmentsArray;
/**
 *  保存扫码时下载的设备
 *
 *  @param equipmentsArray 设备模型数组
 */
- (void)saveQrcodeEquipmentsWithArray:(NSArray*)equipmentsArray;
/**
 *  获取能源仪表扩展属性
 *
 *  @param equipmentId 设备ID
 *
 *  @return 设备模型
 */
- (YWMeterProperty *)meterPropertyWithEquipmentId:(NSString*)equipmentId;
/**
 *  获取设备初始参数
 *
 *  @param  equipmentTypeId 设备类型id
 *
 *  @return 数组
 */
- (NSArray*)equipmentParametersWithEquipmentId:(NSString*)equipmentId;
/**
 *  获取设备数据模型
 *
 *  @param ownCode 设备自编码
 *
 *  @return 设备模型
 */
- (YWEquipment*)equipmentWithOwncode:(NSString*)ownCode;
- (YWEquipment*)equipmentWithFMResultSet:(FMResultSet*)set;
/**
 *  获取设备模型
 *
 *  @param equipmentId 设备id
 *
 *  @return 设备数据模型
 */
- (YWEquipmentType*)equipmentTypeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取设备数据模型
 *
 *  @param equipmentId 设备ID
 *
 *  @return 设备模型
 */
- (YWEquipment*)equipmentWithId:(NSString*)equipmentId;
/**
 *  获取二维码中设备的类型、类型中包含的设备数
 *
 *  @param qrcodeId 二维码Id
 *
 *  @return 二维码类型设备数量模型数组
 */
- (NSArray*)qrcodeEquipmentInfos:(NSString*)qrcodeId;
/**
 *  获取二维码中设备的类型、类型中包含的设备数
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型Id
 *
 *  @return 设备模型
 */
- (NSArray*)qrcodeEquipmentInfos:(NSString*)qrcodeId orLocationId:(NSInteger)locationId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取二维码中设备类型的设备
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithQrcodeId:(NSString*)qrcodeId orLocationId:(NSInteger)locationId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取二维码中设备类型的设备
 *
 *  @param qrcodeId 二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取二维码中所有的设备，且是同类型的设备的二维数组
 *
 *  @param qrcodeId        二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentInNoQrcodeLedgerWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取locationId中所有的设备类型
 *
 *  @param locationId        位置Id
 *  @param equipmentTypeId   设备类型Id
 *  @return 设备模型
 */
- (NSArray*)equipmentTypeArrayWithLocationId:(NSInteger)locationId AndEquipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取QrcodeId中所有的设备类型
 *
 *  @param QrcodeId        二维码Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentTypeArrayWithQrcodeId:(NSString*)qrcodeId;
/**
 *  获取locationId中所有的设备(二维数组)
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentArrayWithLocationId:(NSInteger)locationId;
/**
 *  获取locationId中所有的设备(一维数组)
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentWithLocationId:(NSInteger)locationId;
/**
 *  根据搜索条件筛选设备(一维数组)
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentsWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId page:(NSInteger)page;
/**
 *  根据搜索条件筛选设备
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentArrayWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId page:(NSInteger)page;
/**
 *  根据搜索条件筛选设备(二维数组)，根据这个数组筛选设备类型
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型二维数组
 */
- (NSArray*)equipmentArrayWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;

/**
 *  根据搜索条件筛选设备，返回YWQrcodeEquipmentInfo对象的一维数组
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return YWQrcodeEquipmentInfo数组
 */
- (NSArray *)equipmentInfoArrayWithBuildingId:(NSString *)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取locationId中所有的设备类型
 *
 *  @param locationId        位置Id
 *
 *  @return 设备模型
 */
- (NSArray*)equipmentTypesWithLocationId:(NSInteger)locationId orBuildingId:(NSString*)buildingId;
/**
 *  根据搜索条件查询设备数量
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *
 *  @return 设备模型
 */
- (NSInteger)equipmentCountWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  根据搜索条件查询二维码数
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *
 *  @return 设备模型
 */
- (NSInteger)qrcodeCountWithBuildingId:(NSString*)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  根据搜索条件筛选设备，返回根据locationId排序的二维数组
 *
 *  @param buildingId 楼盘id
 *  @param apartmentId 楼栋id
 *  @param floorId 楼层id
 *  @param locationId 位置id
 *  @param SubSystemTypeId 子系统id
 *  @param equipmentTypeId 设备类型id
 *  @param page 页数
 *
 *  @return 设备模型二维数组
 */
- (NSArray *)equipmentArrayOrderByLocationIdWithBuildingId:(NSString *)buildingId ApartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId locationId:(NSInteger)locationId eqipmentSubSystemType:(NSInteger)SubSystemTypeId equipmentTypeId:(NSInteger)equipmentTypeId  page:(NSInteger)page;
#pragma mark - building table
/**
 *  首次批量新增楼盘数据
 *
 *  @param buildingJsonArray 楼盘Json数据数组
 *
 *  @return 结果
 */
- (BOOL)insertbuildingWithArray:(NSArray*)buildingJsonArray;
- (BOOL)updatebuildingWithJsonArray:(NSArray*)buildingJsonArray;
/**
 *  更新楼盘，楼栋，楼层，位置（只有id和name）
 *
 *  @param buildingId 楼盘Id
 *
 *  @return 楼盘模型
 */
- (BOOL)updateIdAndNameWithBuilding:(YWBuilding *)building apartment:(YWApartment*)apartment floor:(YWFloor*)floor location:(YWLocation*)location;
/**
 *  更新楼盘全量字段(暂时不用)
 *
 *  @param buildingsArray 楼盘YWBuilding数组
 *
 *  @return 结果
 */
//- (BOOL)updateBuildingWithArray:(NSArray*)buildingsArray;

/**
 *  获取楼盘信息
 *
 *  @param buildingId 楼盘Id
 *
 *  @return 楼盘模型
 */
- (YWBuilding*)buildingWithId:(NSString*)buildingId;
/**
 *  获取所有的楼盘
 *
 *  @return 楼盘对象集合
 */
- (NSArray*)allBuilding;
/**
*  获取楼盘信息
*
*  @param locationId 层位置Id
*
*  @return 楼盘模型
*/
- (YWBuilding*)buildingWithLocationId:(NSInteger)locationId;
- (YWBuilding*)buildingWithSet:(FMResultSet*)set;

#pragma mark - apartment table
/**
 *  首次批量新增楼栋数据
 *
 *  @param buildingJsonArray 楼盘Json数据数组
 *
 *  @return 结果
 */
- (BOOL)insertApartmentWithArray:(NSArray*)buildingJsonArray;

/**
 *  更新楼栋全量字段(暂时不用)
 *
 *  @param ApartmentsArray 楼栋数组
 *
 *  @return 结果
 */
- (BOOL)updateApartmentWithArray:(NSArray*)ApartmentsArray;
/**
 *  获取楼栋信息
 *
 *  @param buildingId 楼栋Id
 *
 *  @return 楼栋模型
 */
- (YWApartment*)apartmentWithId:(NSInteger)apartmentId;
- (YWApartment*)apartmentWithFMResultSet:(FMResultSet*)set;
/**
 *  获取楼栋信息
 *
 *  @param buildingId 楼盘Id
 *
 *  @return 楼栋模型数组
 */
- (NSArray*)apartmentsWithbuildingId:(NSString*)buildingId;
#pragma mark - floor table
/**
 *  首次批量新增楼层数据
 *
 *  @param buildingJsonArray 楼盘Json数据数组
 *
 *  @return 结果
 */
- (BOOL)insertFloorWithArray:(NSArray*)buildingJsonArray;

/**
 *  更新楼层全量字段(暂时不用)
 *
 *  @param FloorsArray 楼层数组
 *
 *  @return 结果
 */
- (BOOL)updateFloorWithArray:(NSArray*)FloorsArray;
/**
 *  获取楼层信息
 *
 *  @param buildingId 楼层Id
 *
 *  @return 楼层模型
 */
- (YWFloor*)floorWithId:(NSInteger)floorId;
- (YWFloor*)floorWithFMResultSet:(FMResultSet*)set;
/**
 *  获取楼层信息
 *
 *  @param apartmentId 楼栋Id
 *
 *  @return 楼层模型数组
 */
- (NSArray*)floorsWithApartmentId:(NSInteger)apartmentId;

#pragma mark - location table
/**
 *  首次批量新增层位置数据
 *
 *  @param buildingJsonArray 楼盘Json数据数组
 *
 *  @return 结果
 */
- (BOOL)insertLocationWithArray:(NSArray*)buildingJsonArray;

/**
 *  更新位置全量字段(暂时不用)
 *
 *  @param locationsArray 位置数组
 *
 *  @return 结果
 */
- (BOOL)updateLocationWithArray:(NSArray*)locationsArray;
/**
 *  获取层位置信息
 *
 *  @param locationId 层位置Id
 *
 *  @return 结果
 */
- (YWLocation*)locationWithId:(NSInteger)locationId;
- (YWLocation*)locationWithFMResultSet:(FMResultSet*)set;

/**
 *  获取层位置信息
 *
 *  @param floorId 楼层Id
 *
 *  @return 结果
 */
- (NSArray*)locationsWithFloorId:(NSInteger)floorId;

/**
 *  按条件筛选查询位置
 *
 *  @param buildingId 楼盘Id
 *  @param apartmentId 楼栋Id
 *  @param floorId 楼层Id
 *  @param page 页数
 *
 *  @return 结果
 */
- (NSArray*)locationWithBuildingId:(NSString*)buildingId apartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId page:(NSInteger)page;

/**
 *  查询楼盘
 *
 *  @param lineId 线路Id
 *  @param isKeepWatch 是否是巡更
 *  @param isEquipmentLine 是位置路线还是设备路线
 *
 *  @return 结果
 */
- (NSArray *)buildingArrayWithLineId:(NSInteger)lineId type:(BOOL)isKeepWatch lineType:(BOOL)isEquipmentLine;
/**
 *  查询楼栋
 *
 *  @param buildingId 楼盘Id
 *  @param lineId 线路Id
 *  @param isKeepWatch 是否是巡更
 *  @param isEquipmentLine 是位置路线还是设备路线
 *
 *  @return 结果
 */
- (NSArray *)apartmentArrayWithBuildingId:(NSString*)buildingId LineId:(NSInteger)lineId type:(BOOL)isKeepWatch lineType:(BOOL)isEquipmentLine;
/**
 *  查询楼层
 *
 *  @param apartmentId 楼栋Id
 *  @param lineId 线路Id
 *  @param isKeepWatch 是否是巡更
 *  @param isEquipmentLine 是位置路线还是设备路线
 *
 *  @return 结果
 */
- (NSArray *)floorArrayWithApartmentId:(NSInteger)apartmentId LineId:(NSInteger)lineId type:(BOOL)isKeepWatch lineType:(BOOL)isEquipmentLine;
/**
 *  查询位置
 *
 *  @param floorId 楼层Id
 *  @param lineId 线路Id
 *  @param isKeepWatch 是否是巡更
 *  @param isEquipmentLine 是位置路线还是设备路线
 *
 *  @return 结果
 */
- (NSArray *)locationArrayWithfloorId:(NSInteger)floorId LineId:(NSInteger)lineId type:(BOOL)isKeepWatch lineType:(BOOL)isEquipmentLine;

/**
 *  检测保养任务过滤位置()
 *
 *  @param missionId 任务Id
 *  @param equipmentTypeId 设备类型Id
 *  @param positionType 查询什么类型的位置(1:楼盘/2:楼栋/3:楼层/4:位置)
 *  @param buildingId 楼盘Id
 *  @param apartmentId 楼栋Id
 *  @param floorId 楼层Id
 *
 *  @return 楼盘/楼栋/楼层/位置
 */
- (NSArray *)selectPositionWithMissionId:(NSInteger)missionId equipmentTypeId:(NSInteger)equipmentTypeId positionType:(NSInteger)positionType buildingId:(NSString *)buildingId apartmentId:(NSInteger)apartmentId floorId:(NSInteger)floorId;

#pragma mark - picture table
/**
 *  保存图片信息
 *
 *  @param pictures 图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePictureWithArray:(NSArray*)pictures;
/**
 *  获取设备图片
 *
 *  @param equipmentId 设备Id
 *  @param type 图片类型
 *
 *  @return 图片附件模型
 */
- (NSArray*)picturesWithEquipmentId:(NSString*)equipmentId pictureTroubleType:(YWPictureTroubleType)type;
/**
 *  获取任务图片附件
 *
 *  @param recordId 维保记录Id
 *  @param maintenanceType 维保类型
 *
 *  @return 图片附件模型
 */
- (NSArray*)picturesWithRecordId:(NSInteger)recordId maintenanceType:(NSInteger)maintenanceTypeId;
/**
 *  获取任务图片附件
 *
 *  @param missionId 任务Id
 *  @param maintenanceType 维保类型
 *
 *  @return 图片附件模型
 */
- (NSArray*)picturesWithMissionId:(NSInteger)missionId maintenanceType:(YWMaintenanceType)maintenanceType;

/**
 *  获取维修记录的图片
 *
 *  @param recordId 记录Id
 *  @param type 类型
 *
 *  @return 图片模型数组
 */
- (NSArray*)troublePicturesWithRecordId:(NSInteger)recordId pictureTroubleType:(YWPictureTroubleType)type;
/**
 *  获取维修任务或记录的图片
 *
 *  @param missionId 任务Id
 *  @param type    类型
 *
 *  @return 图片附件
 */
- (NSArray*)picturesWithTroubleMissionId:(NSInteger)missionId pictureTroubleType:(YWPictureTroubleType)type;

#pragma mark - mission table

/**
 *  获取上传失败的检测，保养任务
 *
 *  @return 任务模型数组
 */
- (NSArray *)uploadFailDetectAndUpkeepMission;
/**
 *  根据维保类型获取上传失败的任务
 *
 *  @return 记录模型数组
 */
- (NSArray*)uploadFailedRecordsWithMaintenanceType:(NSInteger)maintenanceType;
/**
 *  通过uniqueTag更新troubleId等部分字段
 *
 *  @return 记录模型数组
 */
- (BOOL)updatePostTroubleId:(YWReportTroubleModel*)reportTrouble uniqueTag:(NSString*)uniqueTag;


/**
 *  获取二维码下所有未完成的任务
 *
 *  @param qrcodeID 二维码Id
 *
 *  @return 任务数组
 */
- (NSArray*)unfinishedMissionsWithQrcodeID:(NSString*)qrcodeID orLocationId:(NSInteger)locationId;
/**
 *  获取二维码下某个类型未完成的任务
 *
 *  @param qrcodeID 二维码Id
 *  @param maintenanceTypeId 维保类型Id
 *
 *  @return 任务数组
 */
- (NSArray*)unfinishedMissionsWithQrcodeID:(NSString*)qrcodeID orLocationId:(NSInteger)locationId andMaintenanceTypeId:(NSInteger)maintenanceTypeId;
/**
 *  获取设备下某个类型未完成的任务
 *
 *  @param equipmentId 设备Id
 *
 *  @param maintenanceTypeId 维保类型Id
 *  @return 任务数组
 */
- (NSArray*)missionsWithEquipmentId:(NSString*)equipmentId andMaintenanceTypeId:(NSInteger)maintenanceTypeId;


/**
 *  设置任务上传失败
 *
 *  @param mission 任务模型
 *
 *  @return 结果
 */
- (BOOL)setUploadFailWithMission:(id)mission;

/**
 *  修改任务的状态（维保任务删除状态，维修的状态）
 *
 *  @param missionId 任务id
 *  @param typeId    任务类型
 *
 *  @return 结果
 */
- (BOOL)mofifyMissionStatusWithMissionId:(NSInteger)missionId maintenanceType:(YWMaintenanceType)typeId;

#pragma mark------------ record table
/**
 *  获取任务的记录 按位置id分组
 *
 *  @param mission 任务
 *
 *  @return 字典    locaionId : NSArray<YWEquipmentMaintenanceRecord>
 */
- (NSDictionary*)detectAndUpkeepRecordsWithMission:(YWMaintenanceMission*)mission;

- (YWEquipmentMaintenanceRecord*)equipmentMaintenanceRecord:(FMResultSet*)set FMDatabase:(FMDatabase*)db;

/**
 *  获取维保记录（巡查、检测、保养）
 *
 *  @param equipmentId 设备Id
 *  @param page 分页数
 *
 *  @return 维保记录模型数组
 */
- (NSArray *)maintenanceRecordsWithEquipmentId:(NSString*)equipmentId andPage:(NSInteger)page;
/**
 *  获取设备巡查记录
 *
 *  @param equipmentId 设备Id
 *  @param page 分页数
 *
 *  @return 维保记录模型数组
 */
- (NSArray *)patrolRecordsWithEquipmentId:(NSString*)equipmentId andPage:(NSInteger)page;

#pragma mark - equipment_detection_record table
/**
 *  保存检测记录
 *
 *  @param equipmentDetectionRecords 检测记录Json模型数组
 *
 *  @return 结果
 */
- (BOOL)saveEquipmentDetectionRecordWithJsonArray:(NSArray*)equipmentDetectionRecordJsons;
/**
 *  保存检测记录
 *
 *  @param equipmentDetectionRecords 检测记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentDetectionRecordWithArray:(NSArray*)equipmentDetectionRecords;
/**
 *  获取检测记录
 *
 *  @param equipmentId 设备Id
 *
 *  @return 维保记录模型数组
 */
- (NSArray*)detectionRecordsWithEquipmentId:(NSString*)equipmentId;
/**
 *  获取检测记录
 *
 *  @param equipmentId 设备Id
 *  @param page
 *  @return 维保记录模型数组
 */
- (NSArray*)detectionRecordArrayWithEquipmentId:(NSString*)equipmentId withPage:(NSInteger)page;
/**
 *  获取检测记录
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型
 *
 *  @return 维保记录模型数组
 */
- (NSArray*)detectionRecordsWithQrcodeId:(NSString*)qrcodeId equipmentTypeId:(NSInteger)equipmentTypeId;
/**
 *  获取任务的检测记录
 *
 *  @param missionId 任务Id
 *  @param equipmentId 设备Id
 *
 *  @return 维保记录模型
 */
- (YWEquipmentMaintenanceRecord*)detectionRecordsWithMissionId:(NSInteger)missionId equipmentId:(NSString*)equipmentId;
/**
 *  更新检测记录的上传状态
 *
 *  @param uploadStatus  上传状态
 *  @param recordId 记录id
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentDetectionRecordUploadStatus:(YWEquipmentMaintenanceRecordUploadStatus)uploadStatus recordId:(NSInteger)recordId;

#pragma mark - equipment_upkeep_record table
/**
 *  保存保养记录
 *
 *  @param equipmentUpkeepRecords 保养记录Json模型数组
 *
 *  @return 结果
 */
- (BOOL)saveEquipmentUpkeepRecordWithJsonArray:(NSArray*)equipmentUpkeepRecordJsons;
/**
 *  保存保养记录
 *
 *  @param equipmentUpkeepRecords 保养记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentUpkeepRecordWithArray:(NSArray*)equipmentUpkeepRecords;
/**
 *  获取保养记录
 *
 *  @param equipmentId 设备Id
 *
 *  @return 维保记录模型数组
 */
- (NSArray*)upkeepRecordsWithEquipmentId:(NSString*)equipmentId;
/**
 *  获取保养记录
 *
 *  @param equipmentId 设备Id
 *  @param page
 *  @return 维保记录模型数组
 */
- (NSArray*)upkeepRecordArrayWithEquipmentId:(NSString*)equipmentId withPage:(NSInteger)page;
/**
 *  获取保养记录
 *
 *  @param qrcodeId        二维码Id
 *  @param equipmentTypeId 设备类型
 *
 *  @return 维保记录模型数组
 */
- (NSArray*)upkeepRecordsWithQrcodeId:(NSString*)qrcodeId equipmentTypeId:(NSInteger)equipmentTypeId;

/**
 *  获取任务的保养记录
 *
 *  @param missionId 任务Id
 *  @param equipmentId 设备Id
 *
 *  @return 维保记录模型
 */
- (YWEquipmentMaintenanceRecord*)upkeepRecordsWithMissionId:(NSInteger)missionId equipmentId:(NSString*)equipmentId;
/**
 *  更新保养记录的上传状态
 *
 *  @param uploadStatus  上传状态
 *  @param recordId 记录id
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentUpkeepRecordUploadStatus:(YWEquipmentMaintenanceRecordUploadStatus)uploadStatus recordId:(NSInteger)recordId;

#pragma mark - equipment_malfunction_record table
/**
 *  保存维修记录
 *
 *  @param equipmentTroubleRecordJsons 维修记录模型Json数组
 *
 *  @return 结果
 */
- (BOOL)saveEquipmentTroubleRecordWithJsonArray:(NSArray*)equipmentTroubleRecordJsons;
/**
 *  保存维修记录
 *
 *  @param equipmentPatrolRecords 维修记录模型数组
 *
 *  @return 结果
 */
- (BOOL)updateEquipmentTroubleRecordWithArray:(NSArray*)equipmentMalfunctionRecords;
/**
 *  按照页数获取维修记录
 *
 *  @param equipmentId 设备Id
 *  @param page 页数
 *
 *  @return 维修记录模型数组
 */
- (NSArray*)troubleRecordArrayWithEquipmentId:(NSString*)equipmentId andPage:(NSInteger)page;
/**
 *  获取维修任务的维修记录
 *
 *  @param missionId 任务Id
 *
 *  @return 维修记录模型
 */
- (YWEquipmentTroubleRecord*)troubleRecordWithMissionId:(NSInteger)missionId;
/**
 *  更新维修记录的上传状态
 *
 *  @param uploadStatus  上传状态
 *  @param recordId 记录id
 *
 *  @return 结果 
 */
- (BOOL)updateEquipmentTroubleRecordUploadStatus:(YWEquipmentMaintenanceRecordUploadStatus)uploadStatus recordId:(NSInteger)recordId;

/**
 *  获取任务未上传的维保记录（不包括维修）
 *
 *  @param mission 任务
 *
 *  @return 维保记录模型数组
 */
- (NSArray*)finishedUnUploadMaintenanceRecordWithMission:(YWMission*)mission;
/**
 *  获取任务未上传的维修记录
 *
 *  @param missionId 任务Id
 *  @return 维保记录模型数组
 */
- (NSArray*)finishedUnUploadTroubleRecord:(NSInteger)missionId;
/**
 *  获取任务的维保记录设备列表
 *
 *  @param mission         任务模型
 *
 *  @return 设备模型数组
 */
- (NSArray*)equipmentsOfMaintentanceMission:(YWMission*)mission;

#pragma mark - handler table
/**
 *  保存项目成员信息
 *
 *  @param buildingMembersJsonArray 项目成员Json
 *
 *  @return 结果
 */
- (BOOL)saveBuildingMembersWithJson:(NSArray*)buildingMembersJsonArray;
/**
 *  保存当前机构的成员
 *
 *  @param organizationMembers 项目成员
 *
 *  @return 结果
 */
- (BOOL)saveOrganizationMembersWithArray:(NSArray*)organizationMembers;
/**
 *  根据楼盘Id获取项目组成员
 *
 *
 *  @return YMHandler模型数组
 */
- (NSArray*)allHandler;
- (BOOL)updateHandlerWithArray:(NSArray*)handlerArray;
- (YWHandler*)handlerWithSet:(FMResultSet*)set;


//二维码编号与位置Id关系表 location_qrcode_rel
#pragma mark - location_qrcode_rel table
/**
 *  获取二维码位置id
 *
 *  @param qrcodeId 二维码编号
 *
 *  @return 位置Id
 */
- (NSInteger)locationIdWithQrcodeId:(NSString*)qrcodeId;

#pragma mark - patrolPicture table
/**
 *  保存巡更巡查等记录的图片
 *
 *  @param patrolPictures 巡更图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPictureWithArray:(NSArray*)patrolPictures;

/**
 *  保存网络请求的巡更巡查等记录图片
 *
 *  @param patrolPictures 巡更图片模型数组
 *
 *  @return 结果
 */
- (BOOL)updatePatrolPictureWithNewWorkData:(NSArray*)patrolPictures;
/**
 *  修改图片的关联ID
 *
 *  params recordId
 */
- (BOOL)updatePatrolPictureRecordId:(NSString*)recordId WithOldRecordId:(NSString*)ordRecordId;
/**
 *  巡更记录图片或者抄表记录图片
 *
 *  @param recordId 记录Id
 *  @param recordType 图片的类型（巡更或者抄表）
 *
 *  @return 巡更图片模型数组
 */
- (NSArray*)recordPictureWithRecordId:(NSString*)recordId recordType:(NSInteger)recordType;

- (YWHandler *)handlerWithUniqueId:(NSInteger)uniqueId;


#pragma mark -attachment table
/**
 *  保存附件
 *
 *  @param attachments 附件模型数组
 *
 *  @return 结果
 */
- (BOOL)updateAttachmentWithAttachments:(NSArray*)attachments;
/**
 *  更新附件的缓存Name
 *
 *  @param attachments 附件模型数组
 *
 *  @return 结果
 */
- (BOOL)updateAttachmenLocalNameWithAttachment:(YWattachment*)attachment;
/**
 *  获取附件
 *
 *  @param recordId 关联Id
 *  @param type 附件类型
 *
 *  @return 结果
 */
- (NSArray *)attachmentWithRecordId:(NSInteger)recordId andType:(YWattachmentType)type;


#pragma mark -departments
/**
 *  获取项目组所有部门
 *
 *
 *  @return YWDepartment模型数组
 */
- (NSArray*)allDepartments;
/**
 *  获取机构下的部门和成员
 *
 *
 *  @return YWDepartment模型数组
 */
- (NSArray *)departmentWithHandlersByOrganizationNo:(NSString*)organizationNo;
/**
 *  获取楼盘下的成员
 *
 *  @param buildingId 楼盘id
 *
 *  @return YWDepartment模型数组
 */
- (NSArray*)departmentWithHandlersByBuildingId:(NSString *)buildingId;
/**
 *  获取部门里的人
 *
 *
 *  @return YWHandler模型数组
 */
- (NSArray*)handlerWithDepartmentIds:(NSString*)departmentIds;
/**
 *  通过uniqueId获取handler
 *
 *
 *  @return YWHandler模型
 */
- (YWHandler*)getHandlerWithUniqueId:(NSInteger)uniqueId;
#pragma mark -informationBank
/**
 *  保存资料
 *
 *  @param informationArray 资料模型数组
 *
 *  @return 无
 */
- (BOOL)saveInformationWithArray:(NSArray*)informationArray;
/**
 *  获取资料
 *
 *  @param page 页数
 *
 *  @return 结果
 */
- (NSArray*)informationArrayWithPage:(NSInteger)page;


#pragma mark - locationRecordView
/**
 *  获取巡查，巡更记录
 *
 *  @param page 页数
 *
 *  @return 结果
 */
- (NSArray*)keepWatchAndInspectRecordsWithLocationId:(NSInteger)locationId andPage:(NSInteger)page;
/**
 *  获取巡查，巡更记录，二维数组，用于设备台账-地址详情
 *
 *  @param locationId 地址Id page 页数
 *  @param page 页数
 *  @return 结果
 */
- (NSArray*)keepWatchAndInspectRecordsInLedgerLocationDetailWithLocationId:(NSInteger)locationId andPage:(NSInteger)page type:(NSInteger)type;

#pragma mark - 巡查,巡更记录和报障关联表
//是否已经有关系
- (BOOL)isExistRelWithTroubleId:(NSInteger)troubleId detailUniqueTag:(NSString*)detailUniqueTag;
//建立关联
- (void)saveRecordAndPostTroubleRelWithtroubleId:(NSInteger)troubleId detailUniqueTag:(NSString*)detailUniqueTag;
//更新关联中的troubleId
- (void)updateRecordAndPostTroubleRelTableUniqueTag:(NSString*)uniqueTag newTroubleId:(NSInteger)newTroubleId;
/**
 *  查询报障Id
 *
 *  @return troubleMission数组
 */
- (NSArray *)troubleIdArrayWithDetailUniqueTag:(NSString *)detailUniqueTag;
/**
 *  查询报障
 *
 *  @return troubleMission数组
 */
- (NSArray *)postTroubleArrayWithDetailUniqueTag:(NSString *)detailUniqueTag;
///**
// *  通过维修任务id串获取维修任务
// *
// *  @return troubleMission数组
// */
//- (NSArray*)troubleMissionArrayWithTroubleIds:(NSArray*)troubleIds;

#pragma mark - 设备的使用方法和范围
- (BOOL)updateEquipmentUseMenthodWithArray:(NSArray*)useMenthodArray;
- (NSTimeInterval)useMenthodMaxUpdateTime;
- (YWEquipmentUseMenthod*)useMenthodWithEquipmentTypeId:(NSInteger)equipmentTypeId;

- (BOOL)updateEquipmentUseRangeWithArray:(NSArray*)useRangeArray;
- (NSTimeInterval)useRangeMaxUpdateTime;
- (YWEquipmentUseRange*)useRangeWithEquipmentTypeId:(NSInteger)equipmentTypeId;
@end
